home *** CD-ROM | disk | FTP | other *** search
/ Oh!X 2001 Spring / Oh!X 2001 Spring Special CD-ROM (Japan) (Track 1).bin / NETBSD / utils / rawrite.lzh / rawrite.c next >
Encoding:
C/C++ Source or Header  |  1996-07-03  |  1.2 KB  |  62 lines

  1. /*
  2.  * rawrite for Human68k
  3.  * -- Write a binary image to 1200K diskette.
  4.  *    by Masaru Oki
  5.  *
  6.  * Usage:
  7.  *    Human prompt> RAWRITE
  8.  *
  9.  *    And follow the prompts.
  10.  */
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <sys/dos.h>
  14. #include <sys/param.h>
  15. #include <ctype.h>
  16.  
  17. int
  18. main()
  19. {
  20.     char fname[MAXPATHLEN];
  21.     FILE *fp;
  22.     int siz;
  23.     char *adr;
  24.     char drive;
  25.  
  26.     printf("RaWrite 1.2 - Write disk file to raw floppy diskette\n");
  27.     printf("Enter source file name: ");
  28.     scanf("%s", fname);
  29.     fp = fopen(fname, "rb");
  30.     if (fp == NULL) {
  31.         perror(fname);
  32.         exit(1);
  33.     }
  34.  
  35.     printf("Enter destination drive: ");
  36.     scanf("%s", fname);
  37.     drive = fname[0];
  38.     drive = (islower(drive) ? toupper(drive) : drive) - 'A';
  39.     printf("Please insert a formatted diskette into ");
  40.     printf("drive %c: and press -ENTER- :", drive + 'A');
  41.     fflush(stdin);
  42.     getchar();
  43.  
  44.     fseek(fp, 0, SEEK_END);
  45.     siz = ftell(fp);
  46.     fseek(fp, 0, SEEK_SET);
  47.     adr = malloc(siz);
  48.     if (adr == NULL) {
  49.         perror("malloc");
  50.         exit(1);
  51.     }
  52.     printf("Reading image");
  53.     fread(adr, 1, siz, fp);
  54.     fclose(fp);
  55.  
  56.     printf("\nWriting image to drive %c:", drive+'A');
  57.     _dos_diskwrt2(adr, drive + 1, 0, siz / 512);
  58.     printf("\nDone.\n");
  59.  
  60.     return 0;
  61. }
  62.